package com.rc.saas.mini.service.rc;

import com.rc.saas.mini.mapper.rc.RcMemberGainGradeRecordMapper;
import com.rc.saas.mini.model.rc.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RcMemberGainGradeRecordServiceImpl implements RcMemberGainGradeRecordService {
    @Autowired
    private RcMemberGainGradeRecordMapper rcMemberGainGradeRecordMapper;

    @Override
    public RcMemberGainGradeRecordMapper getMapper() {
        return rcMemberGainGradeRecordMapper;
    }

    @Override
    public List<RcMemberGainGradeRecord> listCurrentByMemberId(Long memberId) {
        RcMemberGainGradeRecordExample example = new RcMemberGainGradeRecordExample();
        example.createCriteria().andMemberIdEqualTo(memberId);
        example.setOrderByClause("created_time desc");
        return rcMemberGainGradeRecordMapper.selectByExample(example);
    }

    @Override
    public void insertByList(List<RcMemberGainGradeSetting> rcMemberGainGradeSettingList, Long memberId) {
        for( RcMemberGainGradeSetting rcMemberGainGradeSetting:rcMemberGainGradeSettingList){
            RcMemberGainGradeRecord rcMemberGainGradeRecord=new RcMemberGainGradeRecord();
            BeanUtils.copyProperties(rcMemberGainGradeSetting,rcMemberGainGradeRecord);
            rcMemberGainGradeRecord.setMemberId(memberId);
            rcMemberGainGradeRecord.setCreatedTime(new Date());
            rcMemberGainGradeRecord.setLastUpdatedTime(new Date());
            rcMemberGainGradeRecordMapper.insertSelective(rcMemberGainGradeRecord);
        }
    }

    @Override
    public void updateByList() {
        rcMemberGainGradeRecordMapper.updateByList();
    }
}
